package com.shuangti.webdemo.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.stereotype.Component;

@Component
public class mpConfig {

    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        //初始化分页插件 new一个mp的拦截器来实现分页
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //添加分页插件
        PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
        //设置查询数据时一页数据的上限(不是前端传来的数据，这个上限指的是当前端一页要展示的数据比这个大时也只能显示这么多条数据)
        paginationInterceptor.setMaxLimit(10L);
        //添加拦截器实现分页操作
        interceptor.addInnerInterceptor(paginationInterceptor);
        return interceptor;
    }
}
